define(['swiper'],function(){
     //////////////////////////////////////////////////////////
	//选项卡     
	function select() {
		var oli = document.querySelectorAll("ul li")
		var div = document.querySelectorAll(".see")
		//				var i =document.querySelector(".xiahuaxian")
		console.log(div)
		oli.forEach(function(el, index, www) {
			el.addEventListener("click", function() {
				oli.forEach(function(k) {
					k.classList.remove("current")
				})
				div.forEach(function(l) {
					l.classList.remove("active")
				})
				el.classList.add("current")
				div[index].classList.add("active")
			})

		})
	}
	select()
	//////////////////////////////////////////////////////////
	//swiper插件
	var mySwiper = new Swiper('.swiper-container', {
		//			    direction: 'vertical',
		autoplay: 1800, //动画时间
		speed: 300, //滑动速度
		loop: true,

		// 如果需要分页器
		pagination: '.swiper-pagination', 
	})

	//////////////////////////////////////////////////////////
	//获取数据------第一页
	var domain = " https://www.easy-mock.com/mock/5aa77cc42b0894377fc7665a";
	function ajax(method, url, data) {
		var xhr = new XMLHttpRequest();
		xhr.open(method, url);
		xhr.send(data);
		xhr.addEventListener("readystatechange", function() {
			if(xhr.readyState == 4 && xhr.status == 200) {
				add(xhr.response)
			}
		})
	}
	ajax("GET", domain + "/koukoumusic")
	function add(res) {
		var res = JSON.parse(res);
		var shuzu = res.songList;
		console.log(shuzu)
		var template = ""
//				涉及循环,统称处理数据,定义一个函数进行加工
		shuzu.forEach(function(e) {
			var xsd = e.accessnum / 10000
			template += `
   	   	       <li class="js_play_radio">
		            <a class="list_main" href="javascript:;">
		                <div class="list_media">
		                    <img src="${e.picUrl}" alt="">
		                    <span class="listen_count">
		                    	<i class="jj"></i>
		                    	${xsd.toFixed(1)+"万"}
		                    </span>	
		                    <span class="icon icon_play"></span>
		                </div>
		                <div class="list_info">
		                    <h4>${e.songListDesc}</h4>
        					<p>${e.songListAuthor}</p>
		                </div>
		            </a>
		        </li>
   	   	   `
		})
		uuu.innerHTML += template;
	}
	//////////////////////////////////////////////////////////
	//获取数据------第二页
	function second(method, url, data) {
		var xhr = new XMLHttpRequest();
		xhr.open(method, url);
		xhr.send(data);
		xhr.addEventListener("readystatechange", function() {
			if(xhr.readyState == 4 && xhr.status == 200) {
				xdd(xhr.response)
			}
		})
	}
	second("GET", domain + "/koukoumusic1")

	function xdd(res) {
		var res = JSON.parse(res);
		var xedd = res.data.topList;
		console.log(xedd)
		var template = "";
		xedd.forEach(function(e) {
			var xxxx=e.listenCount / 10000
			template += `
   	   	       <li class="topic_item">
			        <div class="topic_main">
			            <a href="javascript:;" class="topic_media">
			                <img src="${e.picUrl}">
			                <span><i class="icon icon_play"></i>${xxxx.toFixed(1)+"万"}</span>
			            </a>
			            <div class="topic_info">
			                <div class="topic_cont">
			                    <h3>${e.topTitle}</h3>
			                    ${topic(e.songList)}
			                </div>
			                <i class="topic_arrow"></i>
			            </div>
			        </div>
			    </li>
   	   	   `
		})
		function topic(list){
			var template = "";
			list.forEach(function(el){
				template+=`
					<p>${el.songname}<span class="text_name">- ${el.singername}</span></p>
				`
			})
			return template;
		}
		ttt.innerHTML += template;
	}
			
})
